<?php get_header();?>
<body>
<div id="topbg"></div>
<div id="container">
	<div id="header">
    	<?php //include TEMPLATEPATH.'/views/banner/view-banner.php';
    	
    	?>
    	<?php include TEMPLATEPATH.'/controllers/banner/controller-banner.php';?>
        <?php include TEMPLATEPATH.'/views/menu/view-menu.php';?>
    </div>
    <?php
   require_once TEMPLATEPATH.'/incs/subscriber/process.php';
	
    $result = null;
    if(isset($_POST['unSubmit']) && $_POST['unSubmit']=="Unsubscriber")
    {
    	$email = $_POST['unEmail'];
    	$code  = $_POST['unCode'];
    	$hidcode  = $_POST['theCode'];
    	
    	if($code==$hidcode)
    	{
    		if(is_email($email))
    		{
    			if(db_check_exists_text("subscriber", "email", $email))
    			{
    				global $wpdb;		
					//$subscriberID = db_select_subscriberID_by_email($email);
					//db_delete_subscriber_by_email($email);   					       		
					$table = $wpdb->prefix."subscriber";
					$query = "DELETE FROM $table WHERE email='".$email."'";
					$wpdb->query($query);
    				$result = "Destroy registered received tin successfully .";
    			}
    			else 
    			{
    				$result = "The Email does not exist.";
    			}
    		}
    		else 
    		{
    			$result = "Email invalid!.";
    		}
    	}
    	else 
    	{
    		$result = 'The code invalid!.';
    	}
    }
    ?>
    <div id="mid">
    	<?php
    	$randCode = rand(11111, 99999); 
    	?>
    	<div id="content" class="homepage">    	
    	<form action="" method="post">
        	<center>
        		<table>
        			<tr>
        				<td colspan="2" align="center" style="font-size: 16px;"><h1>Unsubscriber</h1></td>
        			</tr>
        			<tr>
        				<td colspan="2" align="center"><h1>&nbsp;</h1></td>
        			</tr>
        			<tr>
        				<td colspan="2" align="center" style="color: red;"><?php echo $result;?></td>
        			</tr>
        			<tr>
        				<td>Enter Email Register :</td>
        				<td><input type="text" name="unEmail" value=""/></td>
        			</tr>
        			<tr>
        				<td colspan="2" align="center"><h1>&nbsp;</h1></td>
        			</tr>
        			<tr>
        				<td>Enter the code :</td>
        				<td>
        					<input type="text" name="unCode" value=""/>
        					<label style="color: red; font-weight: bold;"><?php echo $randCode;?></label>
        				</td>
        			</tr>
        			<tr>
        				<td colspan="2" align="center">
        				<input type="hidden" name="theCode" value="<?php echo $randCode;?>"/>
        				</td>
        			</tr>
        			<tr>
        				<td></td>
        				<td><input type="submit" name="unSubmit" value="Unsubscriber"/></td>
        			</tr>
        		</table>
        	</center>
        </form>	
        <?php wp_nonce_field('act_unsubscriber','act_unsubscriber');?>
        </div>
        
        <?php get_sidebar();?>
    </div>
    
    <?php include TEMPLATEPATH.'/views/testimonial/view-home-testimonial.php';?>
    
<?php get_footer();?>    
